CC=g++

AR=ar
ARFLAGS=-cvq

PORT_COMM_ROOT=../../../comm_libs/port_comm
PORT_COMM_LIB=$(PORT_COMM_ROOT)/lib
PORT_COMM_INC=$(PORT_COMM_ROOT)/include

INCS=-I$(PORT_COMM_INC)
LIBS=-L$(PORT_COMM_LIB)

CFLAGS=-c -Wall $(INCS)
LDFLAGS=$(INCS) $(LIBS) -lportcomm
SOURCES=test.cpp
OBJECTS=$(SOURCES:.cpp=.o)
LIB_SOURCES=port_comm.cpp
LIB_OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=test

all: $(PORT_COMM_LIB) $(SOURCES) $(EXECUTABLE)

$(PORT_COMM_LIB): $(PORT_COMM_ROOT)/$(LIB_SOURCES)
	make -C $(PORT_COMM_ROOT) lib

$(EXECUTABLE): $(OBJECTS)
	mkdir -p bin
	$(CC) -o bin/$@ $(OBJECTS) $(LDFLAGS)

%.o: %.cpp
	$(CC) $(CFLAGS) $< -o $@

clean:
	rm -rf *~ bin $(OBJECTS)
	make -C $(PORT_COMM_ROOT) clean

run:
	./bin/$(EXECUTABLE)
